home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / emulator / uae-0.000 / uae-0 / uae-0.6.0 / main.c < prev    next >
C/C++ Source or Header  |  1996-06-12  |  10KB  |  349 lines

  1.  /*
  2.   * UAE - The Un*x Amiga Emulator
  3.   * 
  4.   * Main program 
  5.   * 
  6.   * (c) 1995 Bernd Schmidt, Ed Hanway
  7.   */
  8.  
  9. #include "sysconfig.h"
  10. #include "sysdeps.h"
  11. #include <assert.h>
  12.  
  13. #include "config.h"
  14. #include "options.h"
  15. #include "memory.h"
  16. #include "custom.h"
  17. #include "newcpu.h"
  18. #include "disk.h"
  19. #include "debug.h"
  20. #include "xwin.h"
  21. #include "os.h"
  22. #include "filesys.h"
  23. #include "keybuf.h"
  24. #include "gui.h"
  25.  
  26. int framerate = 1;
  27. int dont_want_aspect = 1;
  28. int use_debugger = 0;
  29. int use_slow_mem = 0;
  30. int use_gfxlib = 0;
  31. int use_xhair = 0;
  32. int use_lores = 0;
  33. int automount_uaedev = 1;
  34. int produce_sound = 1;
  35. int fake_joystick = 0;
  36. KbdLang keyboard_lang = KBD_LANG_US;
  37. #ifndef __DOS__
  38. int screen_res = 3;
  39. #else
  40. int screen_res = 4;
  41. #endif
  42. int color_mode = 0;
  43. ULONG fastmem_size = 0;
  44. char df0[256]="df0.adf", df1[256]="df1.adf", df2[256]="df2.adf", df3[256]="df3.adf";
  45. char romfile[256] = "kick.rom";
  46. #ifndef __DOS__
  47. char prtname[256] = "lpr ";
  48. #else
  49. char prtname[256] = "LPT1:";
  50. #endif
  51.  
  52. /* If you want to pipe Printer output to a file, put something like
  53.  * "cat >>printerfile.tmp" above.
  54.  * The printer support was only tested with the driver "PostScript" on
  55.  * Amiga side, using apsfilter for linux to print ps-data.
  56.  *
  57.  * Note for the DOS-Port: Maybe it's only neccesary to use a
  58.  * -p LPT1: or -p PRN: to print in a DOSBOX. I don't know,
  59.  * I do not use DOS... (please try) -=SR=-
  60.  */
  61.  
  62. #ifndef __bebox__  /* BeOS needs its own startup code */
  63.  
  64. static void usage(void)
  65. {
  66.     printf("UAE - The Un*x Amiga emulator\n");
  67.     printf("Summary of command-line options:\n");
  68.     printf("  -h                       : Print help\n");
  69.     printf("  -m VOLNAME:mount_point   : mount file system at <mount point> as AmigaDOS\n"
  70.        "                             volume VOLNAME:\n");
  71.     printf("  -M VOLNAME:mount_point   : like -m, but mount read-only\n");
  72.     printf("  -a                       : Don't mount the harddisk file automatically.\n"
  73.        "                             Useful only for testing.\n");
  74.     printf("  -s                       : Emulate 1 MB slow memory at 0xC00000\n");
  75.     printf("  -F n                     : Emulate n MB fast memory at 0x200000\n");
  76.     printf("  -f n                     : Set the frame rate to 1/n\n");
  77.     printf("  -D                       : Start up the built-in debugger\n");
  78.     printf("  -[0123] file             : Use file instead of df[0123].adf as disk image file\n");
  79.     printf("  -r file                  : Use file as ROM image instead of kick.rom\n");
  80.     printf("  -J                       : Fake joystick emulation with the numeric pad.\n");
  81. /*   printf("  -g                       : Turn on gfx-lib replacement.\n");*/
  82.     /* We'll have to sort out the following a little better in the future... */
  83.     printf("  -S                       : Turn off sound support (if it is configured)\n");
  84.     printf("  -x                       : Use visible cross-hair cursor (X Windows version)\n");
  85.     printf("  -l lang                  : Set keyboard language to lang, where lang is\n"
  86.        "                             DE, SE, US, FR or IT\n");
  87. #if defined(__unix) && !defined(__DOS__)
  88.     printf("  -p command               : Use command to pipe printer output to.\n");
  89. #else
  90.     printf("  -p filename              : Use filename to save printer output (may be LPT1: ?)\n");
  91. #endif
  92.     printf("  -d mode                  : Select resolution with the mode parameter.\n");
  93.     printf("  -H mode                  : Set the number of colors with the mode parameter.\n");
  94.     printf("\n");
  95. #ifndef __DOS__
  96.     printf("Valid resolutions: 0 (320x200); 1 (320x240); 2 (320x400); 3 (800x600);\n"
  97.        "                   4 (800x600, correct aspect)\n"
  98.        "Valid color modes: 0 (256 colors); 1 (32768 colors); 2 (65536 colors)\n"
  99.        "UAE may choose to ignore the color mode/resolution setting.\n");
  100. #else
  101.     printf("Valid resolutions: 0 (320x200); 1 (320x240); 2 (320x400); 3 (640x480);\n"
  102.        "                   4 (800x600); 5 (800x600, correct aspect)\n"
  103.        "Valid color modes: 0 (256 colors); 1 (32768 colors); 2 (65536 colors)\n"
  104.        "UAE may choose to ignore the color mode/resolution setting.\n");
  105. #endif
  106. }
  107.  
  108. #ifdef __unix
  109.  
  110. static void parse_cmdline(int argc, char **argv)
  111. {
  112.     int c;
  113.     extern char *optarg;
  114.  
  115.     while(((c = getopt(argc, argv, "l:Df:gd:hxF:asSJm:M:0:1:2:3:r:H:p:")) != EOF)) switch(c) {
  116.      case 'h': usage();    exit(0);
  117.  
  118.      case '0': strncpy(df0, optarg, 255); df0[255] = 0;    break;
  119.      case '1': strncpy(df1, optarg, 255); df1[255] = 0; break;
  120.      case '2': strncpy(df2, optarg, 255); df2[255] = 0; break;
  121.      case '3': strncpy(df3, optarg, 255); df3[255] = 0; break;
  122.      case 'r': strncpy(romfile, optarg, 255); romfile[255] = 0; break;
  123.      case 'p': strncpy(prtname, optarg, 255); prtname[255] = 0; break;            
  124.      case 'm':
  125.      case 'M':
  126.     {
  127.         /* mount file system (repeatable)
  128.          * syntax: [-m | -M] VOLNAME:/mount_point
  129.          * example: -M CDROM:/cdrom -m UNIXFS:./disk
  130.          */
  131.         static int mount_seen = 0;
  132.         char buf[256];
  133.         char *s2;
  134.         int readonly = (c == 'M');
  135.  
  136.         if (mount_seen)
  137.         fprintf(stderr, "warning: multiple mounts confuse Kickstart 1.3\n");
  138.         mount_seen = 1;
  139.         strncpy(buf, optarg, 255); buf[255] = 0;
  140.         s2 = strchr(buf, ':');
  141.         if(s2) {
  142.         *s2++ = '\0';
  143. #ifdef __DOS__
  144.         {
  145.             char *tmp;
  146.  
  147.             while ((tmp = strchr(s2, '\\')))
  148.             *tmp = '/';
  149.         }
  150. #endif
  151.         add_filesys_unit(buf, s2, readonly);
  152.         } else {
  153.         fprintf(stderr, "Usage: [-m | -M] VOLNAME:/mount_point\n");
  154.         }
  155.     }
  156.     break;
  157.     
  158.      case 'S': produce_sound = 0; break;
  159.      case 'f': framerate = atoi(optarg); break;
  160.      case 'x': use_xhair = 1; break;
  161.      case 'D': use_debugger = 1; break;
  162.      case 'J': fake_joystick = 1; break;
  163.      case 'a': automount_uaedev = 0; break;
  164.      case 's': use_slow_mem = 1; break;
  165.      case 'g': use_gfxlib = 1; break;
  166.  
  167.      case 'F':
  168.     fastmem_size = atoi(optarg) * 0x100000;
  169.     if (fastmem_size != 0x100000 && fastmem_size != 0x200000 
  170.         && fastmem_size != 0x400000 && fastmem_size != 0x800000) 
  171.     {
  172.         fastmem_size = 0;
  173.         fprintf(stderr, "Unsupported fastmem size!\n");
  174.     }
  175.     
  176.     break;
  177.     
  178.      case 'l':
  179.     if (0 == strcasecmp(optarg, "de"))
  180.         keyboard_lang = KBD_LANG_DE;
  181.     else if (0 == strcasecmp(optarg, "us"))
  182.         keyboard_lang = KBD_LANG_US;
  183.     else if (0 == strcasecmp(optarg, "se"))
  184.         keyboard_lang = KBD_LANG_SE;
  185.     else if (0 == strcasecmp(optarg, "fr"))
  186.         keyboard_lang = KBD_LANG_FR;
  187.     else if (0 == strcasecmp(optarg, "it"))
  188.         keyboard_lang = KBD_LANG_IT;
  189.     break;
  190.     
  191.      case 'd':
  192.     screen_res = atoi(optarg);
  193. #ifndef __DOS__
  194.     if (screen_res >= 0 && screen_res <= 4) {
  195.     } else {
  196.         fprintf(stderr, "Bad video mode selected. Using default.\n");
  197.         screen_res = 3;
  198.     }
  199.     dont_want_aspect = screen_res != 4;
  200. #else
  201.     if (screen_res >= 0 && screen_res <= 5) {
  202.     } else {
  203.         fprintf(stderr, "Bad video mode selected. Using default.\n");
  204.         screen_res = 4;
  205.     }
  206.     dont_want_aspect = screen_res != 5;
  207. #endif
  208.     use_lores = screen_res < 3;
  209.     break;
  210.  
  211.      case 'H':
  212.     color_mode = atoi(optarg);
  213.     if (color_mode < 0 || color_mode > 2) {
  214.         fprintf(stderr, "Bad color mode selected. Using default.\n");
  215.         color_mode = 0;
  216.     }
  217.     break;
  218.     }
  219. }
  220. #endif
  221.  
  222. static void parse_cmdline_and_init_file(int argc, char **argv)
  223. {
  224.     FILE *f;
  225.     char file[256], *home;
  226.     char *buffer,*tmpbuf, *token;
  227.     char smallbuf[256];
  228.     int bufsiz, result;
  229.     int n_args;
  230.     char **new_argv;
  231.     int new_argc;
  232.  
  233.     strcpy(file,"");
  234.  
  235. #if !defined(__DOS__) && !defined(__mac__)
  236.     home = getenv("HOME");
  237.     if (home != NULL && strlen(home) < 240)
  238.     {
  239.     strcpy(file, home);
  240.     strcat(file, "/");
  241.     }
  242. #endif
  243.  
  244. #if defined(__unix) && !defined(__DOS__)
  245.     strcat(file, ".uaerc");
  246. #else
  247.     strcat(file, "uae.rc");
  248. #endif
  249.  
  250.     f = fopen(file,"rb");
  251.     if (f == NULL) {
  252.     parse_cmdline(argc, argv);
  253.     return;
  254.     }
  255.     fseek(f, 0, SEEK_END);
  256.     bufsiz = ftell(f);
  257.     fseek(f, 0, SEEK_SET);
  258.  
  259.     buffer = (char *)malloc(bufsiz+1);
  260.     buffer[bufsiz] = 0;
  261.     if (fread(buffer, 1, bufsiz, f) < bufsiz) {
  262.     fprintf(stderr, "Error reading configuration file\n");
  263.     fclose(f);
  264.     parse_cmdline(argc, argv);
  265.     return;
  266.     }
  267.     fclose(f);
  268.  
  269. #ifdef __DOS__
  270.     {
  271.     char *tmp;
  272.  
  273.     while ((tmp = strchr(buffer, 0x0d)))
  274.         *tmp = ' ';
  275.     while ((tmp = strchr(buffer, 0x0a)))
  276.         *tmp = ' ';
  277.     while (buffer[0] == ' ')
  278.         strcpy(buffer, buffer+1);
  279.     while ((strlen(buffer) > 0) && (buffer[strlen(buffer) - 1] == ' '))
  280.         buffer[strlen(buffer) - 1] = '\0';
  281.     while ((tmp = strstr(buffer, "  ")))
  282.         strcpy(tmp, tmp+1);
  283.     }
  284. #endif
  285.  
  286.     tmpbuf = my_strdup (buffer);
  287.  
  288.     n_args = 0;
  289.     if (strtok(tmpbuf, "\n ") != NULL) {
  290.     do {
  291.         n_args++;
  292.     } while (strtok(NULL, "\n ") != NULL);
  293.     }
  294.     free (tmpbuf);
  295.  
  296.     new_argv = (char **)malloc ((1 + n_args + argc) * sizeof (char **));
  297.     new_argv[0] = argv[0];
  298.     new_argc = 1;
  299.  
  300.     token = strtok(buffer, "\n ");
  301.     while (token != NULL) {
  302.     new_argv[new_argc] = my_strdup (token);
  303.     new_argc++;
  304.     token = strtok(NULL, "\n ");
  305.     }
  306.     for (n_args = 1; n_args < argc; n_args++)
  307.     new_argv[new_argc++] = argv[n_args];
  308.     new_argv[new_argc] = NULL;
  309.     parse_cmdline(new_argc, new_argv);
  310. }
  311.  
  312. int main(int argc, char **argv)
  313. {
  314.     parse_cmdline_and_init_file(argc, argv);
  315.     if (produce_sound && !init_sound()) {
  316.     fprintf(stderr, "Sound driver unavailable: Sound output disabled\n");
  317.     produce_sound = 0;
  318.     }
  319.  
  320.     if (gui_init() < 0) {
  321.     fprintf(stderr, "Failed to initialize the GUI\n");
  322.     /* abort()? Maybe. */
  323.     }
  324.     init_joystick();
  325.     keybuf_init();
  326.     memory_init();
  327.     custom_init();
  328.     DISK_init();
  329.     init_m68k();
  330.     
  331.     if (graphics_init()) {
  332.     MC68000_reset();
  333.  
  334.     debug();
  335.     
  336.     graphics_leave();
  337.     close_joystick();
  338.     }
  339. #ifdef COUNT_INSTRS
  340.     {
  341.     extern void dump_counts(void);
  342.     dump_counts();
  343.     }
  344. #endif
  345.     gui_exit();
  346.     return 0;
  347. }
  348. #endif /* not __bebox__ */
  349.